package com.dattplace.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.dozer.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import com.dattplace.dao.IReleaseVersionDao;
import com.dattplace.model.ReleaseVersion;
import com.dattplace.model.ResultCode;
import com.dattplace.model.ResultData;
import com.dattplace.service.IReleaseVersionService;
import com.dattplace.vo.ReleaseVersionVo;

@Service
public class ReleaseVersionService implements IReleaseVersionService {
	@Autowired
	private IReleaseVersionDao releaseDao;

	@Autowired
	private Mapper mapper;

	@Override
	public ReleaseVersionVo queryVersion(String versionNo) {

		ReleaseVersion version = releaseDao.queryVersion(versionNo);
		return version == null ? null : mapper.map(version, ReleaseVersionVo.class);
	}

	@Override
	public ResultData<Object> releaseVersion(ReleaseVersion version) {
		
		releaseDao.releaseVersion(version);
		return ResultCode.success("发布成功", version);
	}

	@Override
	public void deleteVersion(String versionId) {

		releaseDao.deleteVersion(versionId);
	}

	@Override
	public List<ReleaseVersionVo> queryVersionList(int pageNo, int pageSize, String keyWord) {
		
		List<ReleaseVersionVo> voList =new ArrayList<>();
		List<ReleaseVersion> list =releaseDao.queryVersionList(pageNo,pageSize,keyWord);
		if(!CollectionUtils.isEmpty(list)){
			for(ReleaseVersion v :list){
				ReleaseVersionVo vo =mapper.map(v, ReleaseVersionVo.class);
				voList.add(vo);
			}
		}
		return voList;
	}

	@Override
	public long queryAllVersionCount(String keyWord) {
		return releaseDao.queryAllVersionCount(keyWord);
	}

}
